//
//  WQStatusUserInfoView.swift
//  sanwuWeibo
//
//  Created by 王先强 on 15/12/10.
//  Copyright © 2015年 王先强. All rights reserved.
//

import UIKit
import SnapKit

class WQStatusUserInfoView: UIView {
    
    var statusViewModel: WQStatusViewModel? {
        didSet {
            // TODO - 给子控件赋值
            iconView.sd_setImageWithURL(statusViewModel?.statusUserIconUrl, placeholderImage: statusViewModel?.statusUserDefaultIcon)
            verfiedTypeImageView.image = statusViewModel?.verifiedType
            nameLabel.text = statusViewModel?.statusUserName
            vipView.image = statusViewModel?.statusUserMbrank
            timeLabel.text = statusViewModel?.statusCreatedat
            sourceLabel.text = statusViewModel?.statusSource
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var iconView = UIImageView(image: UIImage(named: "avatar_default_big"))
    private lazy var nameLabel = UILabel(title: "用户名")
    private lazy var vipView = UIImageView(image: UIImage(named: "common_icon_membership_level1"))
    private lazy var timeLabel = UILabel(title: "刚刚")
    private lazy var verfiedTypeImageView = UIImageView()
    lazy var sourceLabel = UILabel(title: "来自 叁伍微博")
}


extension WQStatusUserInfoView {
    private func setupUI() {
        addSubview(iconView)
        addSubview(verfiedTypeImageView)
        addSubview(nameLabel)
        addSubview(vipView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        iconView.backgroundColor = randomColor
        nameLabel.backgroundColor = randomColor
        
        
        iconView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(self.snp_left).offset(homeCellSubViewsMargin)
            make.top.equalTo(self.snp_top).offset(homeCellSubViewsMargin)
            make.width.equalTo(userIconViewWith)
            make.height.equalTo(userIconViewWith)
        }
        
        verfiedTypeImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right).offset(-5)
            make.centerY.equalTo(iconView.snp_bottom).offset(-5)
        }
        
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(iconView.snp_right).offset(homeCellSubViewsMargin)
            make.top.equalTo(self.snp_top).offset(homeCellSubViewsMargin)
        }
        vipView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_right).offset(homeCellSubViewsMargin)
            make.top.equalTo(nameLabel.snp_top)
            
        }
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(nameLabel.snp_left)
            make.bottom.equalTo(iconView.snp_bottom)
        }
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(homeCellSubViewsMargin)
            make.bottom.equalTo(timeLabel.snp_bottom)
        }
        
    }
}